package com.order.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 动态获取配置信息
 * 在Github中添加Webhooks回调地址：http://ip/port/bus/refresh,自动通知
 * */
@RefreshScope
@RestController
public class ConfigJDBCController {

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${spring.datasource.username}")
    private String userName;

    @Value("${spring.datasource.password}")
    private String password;

    @Value("${spring.datasource.driver-class-name}")
    private String driver;


    @GetMapping(value = "/jdbc")
    public String getJDBCInfo() {
        return toString();
    }

    @Override
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("JDBC{")
              .append("URL:")
              .append(url)
              .append(",")
              .append("username")
              .append(userName)
              .append(",")
              .append("password")
              .append(password)
              .append(",")
              .append("driver")
              .append(driver)
              .append("}");
        return buffer.toString();
    }
}
